package annotation;

import java.lang.reflect.Field;

import annotation.FruitColor.Color;

public class Apple {
	@FruitName("apple")
	private String name;
	
	@FruitColor(friutColor=Color.GREEN)
	private String color;
	
	@FruitProvider(id=1)
	private int providerId;

	@FruitProvider(providerName="provider1")
	private String providerName;
	
	@FruitProvider(providerAddr="address")
	private String providerAddress;
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}

	public int getProviderId() {
		return providerId;
	}

	public void setProviderId(int providerId) {
		this.providerId = providerId;
	}

	public String getProviderName() {
		return providerName;
	}

	public void setProviderName(String providerName) {
		this.providerName = providerName;
	}

	public String getProviderAddress() {
		return providerAddress;
	}

	public void setProviderAddress(String providerAddress) {
		this.providerAddress = providerAddress;
	}
	
	public static void main(String[] args) {
		Apple apple = new Apple();
		System.out.println(apple.getName()+apple.getColor()+apple.getProviderId()+apple.getProviderName()+apple.getProviderAddress());
	
		String strFruitName=" 水果名称：";
        String strFruitColor=" 水果颜色：";
        String strFruitProvicer="供应商信息：";
        
        Field[] fields = Apple.class.getDeclaredFields();
        
        for(Field field :fields){
            if(field.isAnnotationPresent(FruitName.class)){
                FruitName fruitName = (FruitName) field.getAnnotation(FruitName.class);
                strFruitName=strFruitName+fruitName.value();
                System.out.println(strFruitName);
            }
            else if(field.isAnnotationPresent(FruitColor.class)){
                FruitColor fruitColor= (FruitColor) field.getAnnotation(FruitColor.class);
                strFruitColor=strFruitColor+fruitColor.friutColor().toString();
                System.out.println(strFruitColor);
            }
            else if(field.isAnnotationPresent(FruitProvider.class)){
                FruitProvider fruitProvider= (FruitProvider) field.getAnnotation(FruitProvider.class);
                strFruitProvicer=" 供应商编号："+fruitProvider.id()+" 供应商名称："+fruitProvider.providerName()+" 供应商地址："+fruitProvider.providerAddr();
                System.out.println(strFruitProvicer);
            }
        }
	}

}
